#include <bits/stdc++.h>
using namespace std;

// #define NEG
constexpr int BUFFER_SIZE = 1 << 20;
class FastIO {
  char getchar() {
    static char input[BUFFER_SIZE], *start = input, *end = input;
    if (start == end) {
      start = input;
      end = start + fread(input, 1, BUFFER_SIZE, stdin);
    }
    return start == end ? 0 : *start ++;
  }
  char buffer[BUFFER_SIZE];
  int len = 0;
  void putchar(char x) {
    if (len == BUFFER_SIZE) flush();
    buffer[len ++] = x;
  }
 public:
  ~FastIO() { flush(); }
  void flush() {
    fwrite(buffer, 1, len, stdout);
    len = 0;
  }
  FastIO& operator>>(string& s) {
    char ch = getchar();
    while (!isgraph(ch)) ch = getchar();
    while (isgraph(ch)) s += ch, ch = getchar();
    return *this;
  }
  FastIO& operator>>(char *p) {
    char ch = getchar();
    while (!isgraph(ch)) ch = getchar();
    while (isgraph(ch)) *p ++ = ch, ch = getchar();
    *p = '\0';
    return *this;
  }
  FastIO& operator>>(char &c) {
    c = getchar();
    while (!isgraph(c)) c = getchar();
    return *this;
  }
  FastIO& operator>>(auto& x) {
    char c = getchar();
#ifdef NEG
    bool neg = false;
    for (; !isdigit(c); c = getchar())
      if (c == '-') neg = true;
    for (x = 0; isdigit(c); x = x * 10 + c - '0', c = getchar());
    if (neg) x = ~x + 1;
#else
    for (; !isdigit(c); c = getchar());
    for (x = 0; isdigit(c); x = x * 10 + c - '0', c = getchar());
#endif
    return *this;
  }
  FastIO& operator<<(auto x) {
#ifdef NEG
    if (x < 0) x = -x, putchar('-');
#endif
    int sta[20], top = 0;
    do {
      sta[top++] = x % 10, x /= 10;
    } while (x);
    while (top) putchar(sta[--top] + '0');
    return *this;
  }
  FastIO& operator<<(char c) { return putchar(c), *this; }
  FastIO& operator<<(const char *p) {
    while (*p) putchar(*p++);
    return *this;
  }
  FastIO& operator<<(const string& s) {
    for (char c : s) putchar(c);
    return *this;
  }
} fio;

int main() {
  int T;
  fio >> T;
  while (T--) {
    stack<unsigned long long> stk;
    int n;
    fio >> n;
    while (n--) {
      string op;
      unsigned long long x;
      fio >> op;
      if (op == "push") {
        fio >> x;
        stk.push(x);
      } else if (op == "pop") {
        if (stk.empty()) {
          cout << "Empty" << '\n';
        } else {
          stk.pop();
        }
      } else if (op == "query") {
        if (stk.empty()) {
          cout << "Anguei!" << '\n';
        } else {
          cout << stk.top() << '\n';
        }
      } else {
        cout << stk.size() << '\n';
      }
    }
  }
}